package utils

import (
	"crypto/sha256"
	"encoding/hex"
	"errors"
	"io"
	"mime/multipart"
)

func GetHash(file multipart.File) (string, error) {
	sha := sha256.New()
	_, err := io.Copy(sha, file)
	if err == nil {
		hash := sha.Sum(nil)
		return hex.EncodeToString(hash), nil
	}

	return "", errors.New("异常")
}
